<template>

	<transition name="el-zoom-in-center">
		<div class="JNPF-preview-main">
			<div class="JNPF-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="10"  class="main" :style="{margin: '0 auto',width:'100%'}">
			<el-form ref="elForm" :model="dataForm" size="medium" label-width="140px" label-position="right" :disabled="!!isDetail">
				<el-col :span="24">
					<el-form-item label="防区编号" prop="fqbh" >
						<el-input v-model="dataForm.fqbh" placeholder="请输入防区编号" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="防区名称" prop="fqmc" >
						<el-input v-model="dataForm.fqmc" placeholder="请输入防区名称" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
        <!--  -->
        <el-col :span="24">
					<el-form-item label="三维坐标" prop="fqmc" >
						<el-input v-model="dataForm.position" placeholder="请输入防区名称" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="所在区域" prop="szqy" >
						<el-input v-model="dataForm.szqy" placeholder="请输入所在区域" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="门禁点IP及端口号" prop="mjdip" >
						<el-input v-model="dataForm.mjdip" placeholder="请输入门禁点IP及端口号" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="所属单位" prop="ssdw" >
						<el-select filterable v-model="dataForm.ssdw" placeholder="请选择所属单位" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in ssdwOptions" :key="index" :label="item.F_FullName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="防区类型" prop="fqlx" >
						<el-input v-model="dataForm.fqlx" placeholder="请输入防区类型" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
			</el-form>
			</el-row>
		</div>
	</transition>
</template>
<script>
import request from '@/utils/request'
import {getDictionaryDataSelector}from '@/api/systemData/dictionary'
import {previewDataInterface}from '@/api/systemData/dataInterface'
export default {
    data() {
      return {
        visible: false,
        isDetail: false,
        dataForm: {
					fqbh:undefined,
					fqmc:undefined,
					szqy:undefined,
					mjdip:undefined,
					ssdw:undefined,
					fqlx:undefined,
          position:undefined
        },
				ssdwOptions:[],
      }
    },
    created() {
		  this.getssdwOptions();
    },
    methods: {
      getssdwOptions()
      {
        previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
          this.ssdwOptions = res.data
        })
      },
      goBack() {
        this.$emit('refresh')
      },
      init(id, isDetail) {
        this.dataForm.id = id || 0;
        this.visible = true;
        this.isDetail = isDetail || false;
        this.$nextTick(() => {
          this.$refs['elForm'].resetFields();
          if (this.dataForm.id) {
            request({
              url: '/api/System/scryDzwlqygl/' + this.dataForm.id,
              method: 'get'
            }).then(res =>{
              this.dataForm = res.data;
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['elForm'].validate((valid) => {
          if (valid) {
            if (!this.dataForm.id) {
              request({
                url: '/api/System/scryDzwlqygl',
                method: 'post',
                data: this.dataForm,
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            } else {
              request({
                url: '/api/System/scryDzwlqygl/' + this.dataForm.id,
                method: 'PUT',
                data: this.dataForm
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            }
          }
        })
      },
    }
  }
  </script>